package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.album.AlbumStat;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumInfoVo;
import com.atguigu.tingshu.vo.album.AlbumListVo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "专辑管理")
@RestController
@RequestMapping("api/album/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class AlbumInfoApiController {

	@Autowired
	private AlbumInfoService albumInfoService;

	@GuiGuLogin
	@PostMapping("/saveAlbumInfo")
	public Result saveAlbumInfo(@RequestBody @Validated AlbumInfoVo albumInfoVo) {
	albumInfoService.saveAlbumInfo(albumInfoVo);
	return Result.ok(ResultCodeEnum.SUCCESS);
	}


	@GuiGuLogin
	@PostMapping("/findUserAlbumPage/{page}/{limit}")
	public Result<IPage<AlbumListVo>> findUserAlbumPage(@PathVariable("page") Integer pageNo,
														@PathVariable("limit") Integer pageSize ,
														@RequestBody AlbumInfoQuery albumInfoQuery){

		IPage<AlbumListVo> albumListVoIPage = albumInfoService.findUserAlbumPage(pageNo, pageSize, albumInfoQuery);
		return Result.build(albumListVoIPage, ResultCodeEnum.SUCCESS);
	}

	@DeleteMapping("removeAlbumInfo/{id}")
	public Result removeAlbumInfoById(@PathVariable("id") Long id) {
		albumInfoService.removeAlbumInfoById(id);
		return Result.ok(ResultCodeEnum.SUCCESS);
	}

	@Operation(summary = "获取专辑信息")
	@GetMapping("getAlbumInfo/{id}")
	public Result<AlbumInfo> getAlbumInfoById(@PathVariable("id") Long id) {
		AlbumInfo albumInfo = albumInfoService.getAlbumInfoById(id);				//	调用服务层方法
		return Result.build(albumInfo,ResultCodeEnum.SUCCESS);
	}

	@Operation(summary = "根据id修改专辑")
	@PutMapping("/updateAlbumInfo/{id}")
	public Result updateById(@PathVariable("id") Long id,@RequestBody AlbumInfoVo albumInfoVo){
		albumInfoService.updateAlbumInfo(id,albumInfoVo);
		return Result.ok();
	}

	@GuiGuLogin
	@GetMapping("/findUserAllAlbumList")
	public Result<List<AlbumInfo>> findUserAllAlbumList(){
	 List<AlbumInfo> albumInfoList =  albumInfoService.findUserAllAlbumList();
		return Result.build(albumInfoList,ResultCodeEnum.SUCCESS);
	}

	@GetMapping(value = "/findByAlbumId/{albumId}")
	public Result<AlbumStatVo> findAlbumStatByAlbumId(@PathVariable(value = "albumId") Long albumId) {
		AlbumStatVo albumStatVo = albumInfoService.findAlbumStatByAlbumId(albumId);
		return Result.build(albumStatVo,ResultCodeEnum.SUCCESS) ;
	}
}

